<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
?>
<?php
	$app = JFactory::getApplication();	
	$products = $this->products;
?>
	<form id="adminForm" name="adminForm" method="post">		
            <div id="toolbar-box">
              <div class="toolbar">
                <ul>
					<li class="toolbar-new"><a href="<?php echo JURI::base(); ?>index.php?option=com_retailshop&view=myshop&task=addnew&shop=<?php echo $_SESSION['shopid']; ?>"><span class="icon-new"></span>New</a></li>
					<li id="toolbar-edit"><a href="#"><span class="icon-edit"></span>Edit</a></li>
					<li id="toolbar_delete_product"><a href="#"><span class="icon-delete"></span>Delete</a></li>
                </ul>
              </div>
              <div class="title">
                <h2>Product Manager: Products</h2>
              </div>
            </div>            
              <div id="search-box">
                <input id="search" type="text" title="Search title. Prefix with ID: to search for a product ID." placeholder="Search..."/>
                <button class="btn" type="submit">Search</button>
                <button onclick="document.id('search').value='';this.form.submit();">Clear</button>
              </div>
              <table width="100%">
                <thead>
                  <tr>
                    <th width="5%"><input type="checkbox" title="Check All" value="" name="checkall-toogle"/></th>
                    <th width="60%"><a href="#">Title</a></th>
                    <th width="20%"><a href="#">Price</a></th>
                    <th width="20%"><a href="#">Deal Price</a></th>
                  </tr>
                </thead>
                <tbody id="table_body">
					<?php foreach($products as $product){ ?>
					<tr>
						<td width="5%"><input type="checkbox" value="<?php echo $product->id; ?>" name="ckbproduct[]"/></td>
						<td><a href ="index.php?option=com_retailshop&view=myshop&task=addnew&id=<? echo $product->id; ?>"><?php echo $product->name; ?></a></td>
						<td class="table-price"><?php echo number_format($product->price,2); ?> $</td>
						<td class="table-deal-price"><?php echo number_format($product->promotion,2); ?> %</td>
					</tr>
					<?php }?>
                </tbody>
                <tfoot>					
                  <tr>
                    <td colspan="4">
                        <?php if(count($products) != 0): ?>
                        <div class="pagination">
						<div class="page">
							Page
							<select size="1" class="inputbox" name="limit" id="limit_product_page">
							<?php for($i=1; $i<count($products)/10 + 1; $i++) { ?>
								<option value="<?php echo $i; ?>"><?php echo $i; ?></option>
							<?php } ?>
                            </select>
						  </div>						
                          <div class="limit">Display #
                            <select size="1" class="inputbox" name="limit" id="limit_product">
                              <option value="5">5</option>
                              <option value="10" selected="selected">10</option>
                              <option value="15">15</option>
                              <option value="20">20</option>
                              <option value="25">25</option>
                              <option value="30">30</option>
                              <option value="50">50</option>
                              <option value="100">100</option>
                              <option value="0">All</option>
                            </select>
                          </div>
                      	</div>
                        <?php endif; ?>
                      </td>
                  </tr>
                </tfoot>
              </table>
            </form>          
<script type="text/javascript">
	$(document).ready(function(){		
		$("#limit_product").change(function(){
			var limit =  $(this).val();	
			var page = '';
			for(var i = 1; i < <?php echo count($products); ?> /limit + 1; i++){
				page += '<option value="'+ i +'">'+ i +'</option>';
			}
			$('#limit_product_page').html(page);
			$.ajax({	
				url:"index.php?option=com_retailshop&view=myshop&task=limit&value="+limit,
				data:{limit:limit},
				type: "POST",
				dataType: "html",
				success:function(data) {									
					$('#table_body').html(data);
				},
				error: function (){
					alert('loi');
				}
			});					
		});	
		$("#limit_product_page").change(function(){
			var page =  $(this).val();	
			var limit = $('#limit_product').val();
			$.ajax({	
				url:"index.php?option=com_retailshop&view=myshop&task=limit",
				data:{page:page,limit:limit},
				type: "POST",
				dataType: "html",
				success:function(data) {									
					$('#table_body').html(data);
				},
				error: function (){
					alert('loi');
				}
			});					
		});	
	});
</script>
